package com.lingxu.api.ztb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingxu.api.ztb.mapper.LandUseSpecialReviewMapper;
import com.lingxu.api.ztb.model.LandUseSpecialReview;
import com.lingxu.api.ztb.model.vo.PreDesignReviewVO;
import com.lingxu.api.ztb.service.ILandUseSpecialReviewService;
import com.lingxu.api.ztb.model.vo.LandUseSpecialReviewVO;



import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.metadata.IPage;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * 用地专题审查表 服务实现类
 *
 * @author admin
 * @since 2025-08-14
 */
@Slf4j
@Service
public class LandUseSpecialReviewServiceImpl extends ServiceImpl<LandUseSpecialReviewMapper, LandUseSpecialReview>  implements ILandUseSpecialReviewService {

    @Resource
    private LandUseSpecialReviewMapper landUseSpecialReviewMapper;

    @Transactional(readOnly = true)
    @Override
    public IPage<LandUseSpecialReviewVO> queryPageList(LandUseSpecialReviewVO query) {
        Page<LandUseSpecialReviewVO> page = new Page<LandUseSpecialReviewVO>(query.getPageNo(), query.getPageSize());
        return landUseSpecialReviewMapper.pageList(page,query);
    }


    @Transactional(readOnly = true)
    @Override
    public List<LandUseSpecialReviewVO> list(LandUseSpecialReviewVO query) {
        return landUseSpecialReviewMapper.selectLandUseSpecialReviewList(query);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(Set<String> ids) {
        if (CollectionUtils.isNotEmpty(ids)) {
            landUseSpecialReviewMapper.deleteBatchIds(ids);
        }
    }

    @Override
    public IPage<LandUseSpecialReviewVO> getPageList(LandUseSpecialReviewVO query) {
        int offset = (int) ((query.getPageNo() - 1) * query.getPageSize());
        int pageSize = Math.toIntExact(query.getPageSize());
        int total = landUseSpecialReviewMapper.countUnionList(query);
        List<LandUseSpecialReviewVO> records = landUseSpecialReviewMapper.selectUnionList(query, offset, pageSize);
        Page<LandUseSpecialReviewVO> page = new Page<>(query.getPageNo(), pageSize);
        page.setRecords(records);
        page.setTotal(total);
        return page;
    }

}
